@ECHO OFF
SET entryText=%1
SET outputText=%2
SET finalLog=%3
SET finalError=%4

ECHO.
ECHO Running First Module
%~dp0Modulo1\Modulo1.exe %entryText% Output1.txt Log1.txt Error1.txt


ECHO Running Second Module
%~dp0Modulo2\Modulo2.exe Output1.txt Output2.txt Log2.txt Error2.txt


ECHO Running Third Module
%~dp0Modulo3\Modulo3.exe Output2.txt Output3.txt Log3.txt Error3.txt


ECHO Running Fourth Module
%~dp0Modulo4\Modulo4.exe Output3.txt Output4.txt Log4.txt Error4.txt
REM ECHO Running Fourth Module
REM %~dp0Modulo4\Modulo4.exe Output3.txt Output4.txt Log4.txt Error4.txt

ECHO Running Fifth Module
%~dp0Modulo5\Modulo5.exe Output4.txt FinalOutput.txt Log5.txt Error5.txt
REM ECHO Running Fifth Module
REM %~dp0Modulo5\Modulo5.exe Output4.txt %outputText% Log5.txt Error5.txt

REM Merge Log files into FinalLog
copy /b Log*.txt %3 >nul 2>&1
REM Merge Error files into FinalError
copy /b Error*.txt %4 >nul 2>&1

REM Create directory to save output of run.
mkdir Run 2> NUL
move /Y %outputText% Run >nul 2>&1
move /Y %finalLog% Run >nul 2>&1
move /Y %finalError% Run >nul 2>&1

mkdir Run\LogFiles 2> NUL
move /Y Log* Run\LogFiles >nul 2>&1

mkdir Run\ErrorFiles 2> NUL
move /Y Error* Run\ErrorFiles >nul 2>&1

mkdir Run\OutputFiles 2> NUL
move /Y Output* Run\OutputFiles >nul 2>&1

ECHO.
ECHO Finished!
ECHO.

ECHO Press any key to exit.
pause>null
